package com.example.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys.entity.OperLog;
import com.example.sys.mapper.OperLogMapper;
import com.example.sys.service.OperLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sys.vo.OperLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 操作日志记录 服务实现类
 * </p>
 *
 * @author anan
 * @since 2019-06-20
 */
@Service
public class OperLogServiceImpl extends ServiceImpl<OperLogMapper, OperLog> implements OperLogService {

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public IPage<OperLog> selectPage(OperLogVo operLogVo) {
        IPage<OperLog> iPage = new Page<>(operLogVo.getPage(), operLogVo.getLimit());
        QueryWrapper<OperLog> wrapper = new QueryWrapper<>();
        if (operLogVo.getStartDate()!=null && operLogVo.getEndDate()!=null){
            wrapper.between("login_time", operLogVo.getStartDate(), operLogVo.getEndDate());
        }else if (operLogVo.getStartDate()!=null){
            wrapper.ge("login_time", operLogVo.getStartDate());
        } else if (operLogVo.getEndDate() != null) {
            wrapper.le("login_time", operLogVo.getStartDate());
        }
        if (!StrUtil.hasEmpty(operLogVo.getTitle()))
            wrapper.like("title", operLogVo.getTitle());
        if (!StrUtil.hasEmpty(operLogVo.getOperName()))
            wrapper.like("oper_name", operLogVo.getOperName());
        if (operLogVo.getOperatorType()!=null)
            wrapper.like("operator_type", operLogVo.getOperatorType());
        return operLogMapper.selectPage(iPage, wrapper);
    }
}
